home *** CD-ROM | disk | FTP | other *** search
/ CD Actual 3 / CD ACTUAL 3.iso / linux / incoming / jstools-.6v3 / jstools- / jstools-tk3.6v3.0 / lib / jedit_menus.tcl < prev    next >
Encoding:
Text File  |  1995-03-14  |  13.4 KB  |  411 lines

  1. # jedit_menus.tcl - menus for jedit, a tk-based editor
  2. # Copyright 1992-1995 by Jay Sekora.  All rights reserved, except 
  3. # that this file may be freely redistributed in whole or in part 
  4. # for non-profit, noncommercial use.
  5.  
  6. ######################################################################
  7. # jedit:mkmenus - create menubar
  8. ######################################################################
  9.  
  10. proc jedit:mkmenus {mb t} {
  11.   j:debug
  12.   global JEDIT_MODEPREFS
  13.   
  14.   set mode [jedit:get_mode $t]
  15.   
  16.   set all_menus {editor file edit prefs abbrev filter format mode1 mode2}
  17.   set displayed_menus {}
  18.   
  19.   foreach menu $all_menus {
  20.     if [winfo exists $mb.$menu] {
  21.       destroy $mb.$menu
  22.     }
  23.     if $JEDIT_MODEPREFS($mode,menu,$menu) {
  24.       catch {
  25.         jedit:mkmenu:$menu $mb.$menu $t
  26.         pack $mb.$menu -in $mb -side left
  27.         lappend displayed_menus $mb.$menu
  28.       }
  29.     }
  30.   }
  31.   
  32.   # check for user menu proc - normally in ~/.tk/jeditrc.tcl
  33.   #
  34.   if $JEDIT_MODEPREFS($mode,menu,user) {
  35.     if {[info procs jedit:mkmenu:user] != {}} {
  36.       if [winfo exists $mb.user] {
  37.         destroy $mb.user
  38.       }
  39.       jedit:mkmenu:user $mb.user $t
  40.       pack $mb.user -in $mb -side right
  41.       lappend displayed_menus $mb.user
  42.     }
  43.   }
  44.   
  45.   eval tk_menuBar $mb $displayed_menus
  46. }
  47.  
  48. proc jedit:mkmenu:editor {menu t} {
  49.   global JEDIT_MODEPREFS
  50.   
  51.   menubutton $menu -text {Editor} -menu $menu.m
  52.   
  53.   menu $menu.m
  54.   
  55.   $menu.m add command -label {Help} -accelerator {[h]} \
  56.     -command "jedit:cmd:help $t"
  57.   $menu.m add command -label {About the Editor . . .} \
  58.     -command "jedit:cmd:about $t"
  59.   $menu.m add command -label {Global Preferences . . .} \
  60.     -accelerator {[G]} \
  61.     -command {j:global_pref_panel}
  62.   $menu.m add command -label {Editor Preferences . . .} \
  63.     -accelerator {[P]} \
  64.     -command "jedit:cmd:edit_prefs $t"
  65.   $menu.m add command -label {Mode Preferences . . .} \
  66.     -command "jedit:cmd:mode_prefs $t"
  67.   $menu.m add command -label {Mode . . .} -accelerator {[m]} \
  68.     -command "jedit:cmd:ask_mode $t"
  69.   $menu.m add separator
  70.   $menu.m add command -label {Issue Tcl Command . . .} \
  71.     -accelerator {[T]} -command {j:prompt_tcl}
  72.   $menu.m add command -label {Issue Unix Command . . .} \
  73.     -accelerator {[U]} -command {j:prompt_unix}
  74.   $menu.m add separator
  75.   $menu.m add command -label {New Window} -accelerator {[n]} \
  76.     -command "jedit:cmd:new_window $t"
  77.   $menu.m add command -label {Done} \
  78.     -command "jedit:cmd:done $t"
  79.   $menu.m add command -label {Close Window} -accelerator {[w]} \
  80.     -command "jedit:cmd:close $t"
  81.   $menu.m add command -label {Quit} -accelerator {[q]} \
  82.     -command "jedit:cmd:quit $t"
  83. }
  84.  
  85. proc jedit:mkmenu:file {menu t} {
  86.   global JEDIT_MODEPREFS
  87.   
  88.   menubutton $menu -text {File} -menu $menu.m
  89.   
  90.   menu $menu.m
  91.   
  92.   $menu.m add command -label {Load . . .} -accelerator {[l]} \
  93.     -command "jedit:cmd:load $t"
  94.   $menu.m add command -label {Save} -accelerator {[s]} \
  95.     -command "jedit:cmd:save $t"
  96.   $menu.m add command -label {Save As . . .} -accelerator {[S]} \
  97.     -command "jedit:cmd:saveas $t"
  98.   $menu.m add command -label {Print . . .} -accelerator {[p]} \
  99.     -command "jedit:cmd:print $t"
  100.   $menu.m add separator
  101.   $menu.m add command -label {Insert File . . .} -accelerator {[i]} \
  102.     -command "jedit:cmd:insfile $t"
  103. }
  104.  
  105. proc jedit:mkmenu:edit {menu t} {
  106.   global JEDIT_MODEPREFS
  107.   
  108.   menubutton $menu -text {Edit} -menu $menu.m
  109.   
  110.   menu $menu.m
  111.   
  112.   $menu.m add command -label {Cut} -accelerator {[x]} \
  113.     -command "jedit:cmd:cut $t"
  114.   $menu.m add command -label {Copy} -accelerator {[c]} \
  115.     -command "jedit:cmd:copy $t"
  116.   $menu.m add command -label {Paste} -accelerator {[v]} \
  117.     -command "jedit:cmd:paste $t"
  118.   $menu.m add command -label {Note} -accelerator {[N]} \
  119.     -command "jedit:cmd:note $t"
  120.   $menu.m add command -label {Insert X Selection} -accelerator {[V]} \
  121.     -command "jedit:cmd:xpaste $t"
  122.   $menu.m add command -label {Select All} -accelerator {[a]} \
  123.     -command "jedit:cmd:select_all $t"
  124.   $menu.m add separator
  125.   $menu.m add command -label {Find . . .} -accelerator {[f]} \
  126.     -command "jedit:cmd:find $t"
  127.   $menu.m add command -label {Find Again} -accelerator {[g]} \
  128.     -command "jedit:cmd:find_again $t"
  129.   $menu.m add separator
  130.   $menu.m add command -label {Go to Line . . .} -accelerator {[L]} \
  131.     -command "jedit:cmd:go_to_line $t"
  132.   $menu.m add command \
  133.     -label {Show Current Position . . .} -accelerator {[C]} \
  134.     -command "jedit:cmd:current_line $t"
  135.   $menu.m add separator
  136.   #
  137.   # the following three SHOULD BE affected by later configuration, and a trace
  138.   # on JEDIT_PREFS(undolevel) (but aren't)
  139.   #
  140.   $menu.m add command -label {Checkpoint} \
  141.     -command "jedit:cmd:save_checkpoint $t"
  142.   $menu.m add command -label {Undo} -accelerator {[z]} \
  143.     -command "jedit:cmd:undo $t"
  144.   $menu.m add command -label {Redo} -accelerator {[Z]} \
  145.     -command "jedit:cmd:redo $t"
  146. }
  147.  
  148. proc jedit:mkmenu:prefs {menu t} {
  149.   global JEDIT_MODEPREFS
  150.   
  151.   set mode [jedit:get_mode $t]
  152.   
  153.   menubutton $menu -text {Prefs} -menu $menu.m
  154.   
  155.   menu $menu.m
  156.   
  157.   $menu.m add checkbutton -label {Save/load visual state} \
  158.     -variable JEDIT_MODEPREFS($mode,savestate) \
  159.     -command "jedit:apply_prefs \[jedit:text_to_top $t\]"
  160.   $menu.m add checkbutton -label {Break lines on <space>} \
  161.     -variable JEDIT_MODEPREFS($mode,autobreak) \
  162.     -command "jedit:apply_prefs \[jedit:text_to_top $t\]"
  163.   $menu.m add checkbutton -label {Indent lines on <Return>} \
  164.     -variable JEDIT_MODEPREFS($mode,autoindent) \
  165.     -command "jedit:apply_prefs \[jedit:text_to_top $t\]"
  166.   $menu.m add separator
  167.   $menu.m add radiobutton -label {Don't wrap lines} \
  168.     -variable JEDIT_MODEPREFS($mode,textwrap) -value none \
  169.     -command "jedit:apply_prefs \[jedit:text_to_top $t\]"
  170.   $menu.m add radiobutton -label {Wrap lines anywhere} \
  171.     -variable JEDIT_MODEPREFS($mode,textwrap) -value char \
  172.     -command "jedit:apply_prefs \[jedit:text_to_top $t\]"
  173.   $menu.m add radiobutton -label {Wrap lines at words} \
  174.     -variable JEDIT_MODEPREFS($mode,textwrap) -value word \
  175.     -command "jedit:apply_prefs \[jedit:text_to_top $t\]"
  176. }
  177.  
  178. proc jedit:mkmenu:abbrev {menu t} {
  179.   global JEDIT_MODEPREFS
  180.   
  181.   set mode [jedit:get_mode $t]
  182.   
  183.   menubutton $menu -text {Abbrev} -menu $menu.m
  184.   
  185.   menu $menu.m
  186.   
  187.   $menu.m add checkbutton -label {Static Abbreviation} \
  188.     -accelerator {[Space]} \
  189.     -variable JEDIT_MODEPREFS($mode,sabbrev) -onvalue 1 -offvalue 0
  190.   $menu.m add checkbutton -label {Dynamic Abbreviation} \
  191.     -accelerator {[Tab]} \
  192.     -variable JEDIT_MODEPREFS($mode,dabbrev) -onvalue 1 -offvalue 0
  193.   $menu.m add separator
  194.   $menu.m add command -label {Expand Static Abbreviation} \
  195.     -accelerator {[']} \
  196.     -command "jedit:cmd:sabbrev $t"
  197.   $menu.m add command -label {Expand Dynamic Abbreviation} \
  198.     -accelerator {[;]} \
  199.     -command "jedit:cmd:dabbrev $t"
  200.   $menu.m add separator
  201.   $menu.m add command -label {Edit Static Abbreviations} \
  202.     -command "jedit:cmd:edit_abbrevs"
  203.   $menu.m add command -label {Reread Static Abbreviations} \
  204.     -command "jedit:cmd:read_abbrevs"
  205. }
  206.  
  207. proc jedit:mkmenu:filter {menu t} {
  208.   global JEDIT_MODEPREFS
  209.   
  210.   menubutton $menu -text {Filter} -menu $menu.m
  211.   
  212.   menu $menu.m
  213.   
  214.   $menu.m add command -label {Format Lines with `fmt'} \
  215.     -accelerator {[F]} \
  216.     -command "jedit:pipe $t {fmt}"
  217.   $menu.m add separator
  218.   #
  219.   # following few entries are tricky syntactically.  the commands are in
  220.   # quotes, so double-quote-style substitution is done on the ENTIRE
  221.   # command (braces aren't special in quotes).
  222.   #
  223.   $menu.m add command -label {Indent} \
  224.     -accelerator {[]]} \
  225.     -command "jedit:text_regsub $t {(^|\n)} {\\1  }"
  226.   $menu.m add command -label {Quote Email} \
  227.     -command "jedit:text_regsub $t {(^|\n)} {\\1> }"
  228.   $menu.m add command -label {Unindent/Unquote} \
  229.     -accelerator {[[]} \
  230.     -command "jedit:text_regsub $t {(^|\n)\[> \] } {\\1}"
  231.   #
  232.   $menu.m add separator
  233.   $menu.m add command -label {Capitalise} \
  234.     -command "jedit:pipe $t {tr {\[a-z\]} {\[A-Z\]}}"
  235.   $menu.m add command -label {Lowercase} \
  236.     -command "jedit:pipe $t {tr {\[A-Z\]} {\[a-z\]}}"
  237.   $menu.m add command -label {Toggle Case} \
  238.     -command "jedit:pipe $t {tr {\[A-Z\]\[a-z\]} {\[a-z\]\[A-Z\]}}"
  239.   $menu.m add separator
  240.   $menu.m add command -label {Sort by ASCII Sequence} \
  241.     -command "jedit:pipe $t {sort}"
  242.   $menu.m add command -label {Sort Numerically} \
  243.     -command "jedit:pipe $t {sort -n}"
  244.   $menu.m add command -label {Sort Alphabetically} \
  245.     -command "jedit:pipe $t {sort -if}"
  246.   $menu.m add separator
  247.   $menu.m add command -label {Pipe Through . . .} -accelerator {[|]} \
  248.      -command "jedit:cmd:run_pipe $t"
  249.   $menu.m add command -label {Insert Output of . . .} -accelerator {[!]} \
  250.      -command "jedit:cmd:run_command $t"
  251. }
  252.  
  253. proc jedit:mkmenu:format {menu t} {
  254.   global JEDIT_MODEPREFS jedit_mkmenu_format
  255.   
  256.   menubutton $menu -text {Format} -menu $menu.m
  257.   
  258.   menu $menu.m
  259.   
  260.   jedit:mkmenu:format:font $menu.m.font $t
  261.   jedit:mkmenu:format:background $menu.m.background $t
  262.   jedit:mkmenu:format:foreground $menu.m.foreground $t
  263.   jedit:mkmenu:format:characters $menu.m.characters $t
  264.   
  265.   $menu.m add command -label "Rich Cut" -command "jedit:cmd:rich_cut $t"
  266.   $menu.m add command -label "Rich Copy" -command "jedit:cmd:rich_copy $t"
  267.   $menu.m add command -label "Rich Paste" -command "jedit:cmd:rich_paste $t"
  268.   $menu.m add separator
  269.   $menu.m add cascade -label "Font" -menu $menu.m.font
  270.   $menu.m add cascade -label "Background" -menu $menu.m.background
  271.   $menu.m add cascade -label "Foreground" -menu $menu.m.foreground
  272.   $menu.m add checkbutton -label "Underline" \
  273.     -variable jedit_mkmenu_format(underline) \
  274.     -command "jedit:format:underline $t \$jedit_mkmenu_format(underline)"
  275.   $menu.m add separator
  276.   $menu.m add command -label {Type in Plain} \
  277.     -command "j:tag:set_tags $t {}; set jedit_mkmenu_format(underline) 0"
  278.   $menu.m add separator
  279.   $menu.m add cascade -label "Characters" -menu $menu.m.characters
  280.   $menu.m add separator
  281.   $menu.m add command -label "Rich Save As . . ." -command "j:tc:saveas $t"
  282.   $menu.m add separator
  283.   $menu.m add command -label "Print PostScript" \
  284.     -command "jedit:cmd:print_postscript $t"
  285. }
  286.  
  287. proc jedit:mkmenu:format:font {menu t} {
  288.   global JEDIT_MODEPREFS
  289.   
  290.   menu $menu
  291.   
  292.   $menu add command -label {Roman} \
  293.     -accelerator {[R]} \
  294.     -command "jedit:font:roman $t"
  295.   $menu add command -label {Italic} \
  296.     -accelerator {[I]} \
  297.     -command "jedit:font:italic $t"
  298.   $menu add command -label {Bold} \
  299.     -accelerator {[B]} \
  300.     -command "jedit:font:bold $t"
  301.   $menu add command -label {Bold Italic} \
  302.     -accelerator {[X]} \
  303.     -command "jedit:font:bolditalic $t"
  304.   $menu add command -label {Typewriter} \
  305.     -accelerator {[M]} \
  306.     -command "jedit:font:typewriter $t"
  307.   $menu add separator
  308.   $menu add command -label {Level 0 Heading} \
  309.     -command "jedit:font:heading0 $t"
  310.   $menu add command -label {Level 1 Heading} \
  311.     -command "jedit:font:heading1 $t"
  312.   $menu add command -label {Level 2 Heading} \
  313.     -command "jedit:font:heading2 $t"
  314.   $menu add command -label {Level 3 Heading} \
  315.     -command "jedit:font:heading3 $t"
  316.   $menu add command -label {Level 4 Heading} \
  317.     -command "jedit:font:heading4 $t"
  318.   $menu add command -label {Level 5 Heading} \
  319.     -command "jedit:font:heading5 $t"
  320.   $menu add separator
  321.   $menu add command -label {Plain Font} \
  322.     -command "jedit:font:plain $t"
  323. }
  324.  
  325. proc jedit:mkmenu:format:background {menu t} {
  326.   global JEDIT_MODEPREFS
  327.   
  328.   menu $menu
  329.   
  330.   $menu add command -label {Plain Background} \
  331.     -command "jedit:format:background:clear $t"
  332.   $menu add separator
  333.   
  334.   set colours {
  335.     Black Grey25 Grey33 Grey50 Grey66 Grey75 White
  336.     Red Green Blue Cyan Magenta Yellow
  337.     LemonChiffon Gold SpringGreen
  338.   }
  339.   
  340.   foreach colour $colours {
  341.     $menu add command -label $colour \
  342.       -command [list jedit:format:background $t $colour]
  343.   }
  344. }
  345.  
  346. proc jedit:mkmenu:format:foreground { menu t } {
  347.   global JEDIT_MODEPREFS
  348.   
  349.   menu $menu
  350.   
  351.   $menu add command -label {Plain Foreground} \
  352.     -command "jedit:format:foreground:clear $t"
  353.   $menu add separator
  354.   
  355.   set colours {
  356.     Black Grey25 Grey33 Grey50 Grey66 Grey75 White
  357.     Red Green Blue Cyan Magenta Yellow
  358.     LemonChiffon Gold SpringGreen
  359.   }
  360.   
  361.   foreach colour $colours {
  362.     $menu add command -label $colour \
  363.       -command [list jedit:format:foreground $t $colour]
  364.   }
  365. }
  366.  
  367. proc jedit:mkmenu:format:characters { menu t } {
  368.   menu $menu
  369.   
  370.   $menu add command -label "Select Character . . ." \
  371.     -command "jedit:cmd:char_panel $t"
  372.   $menu add command -label "Insert Hyphen" \
  373.     -accelerator {[-]} \
  374.     -command "jedit:cmd:hyphen $t"
  375.   $menu add command -label "Insert Copyright Symbol" \
  376.     -command "jedit:cmd:copyright $t"
  377. }
  378.  
  379. proc jedit:mkmenu:mode1 { menu t } {
  380.   set mode [jedit:get_mode $t]
  381.   
  382.   #####################  should check for proc, not just catch! ##############
  383.   catch {eval mode:$mode:mkmenu1 $menu $t}
  384. }
  385.  
  386. proc jedit:mkmenu:mode2 { menu t } {
  387.   set mode [jedit:get_mode $t]
  388.   
  389.   #####################  should check for proc, not just catch! ##############
  390.   catch {eval mode:$mode:mkmenu2 $menu $t}
  391. }
  392.  
  393. ######################################################################
  394. # jedit:menus:prefs w mode- return mode menu preferences metawidget
  395. ######################################################################
  396.  
  397. proc jedit:prefs:menus { w mode } {
  398.   global JEDIT_MODEPREFS
  399.   
  400.   frame $w
  401.   foreach menu {file edit prefs abbrev filter format mode1 mode2 user} {
  402.     checkbutton $w.$menu -relief flat -anchor w \
  403.       -text "Show $menu menu" \
  404.       -variable JEDIT_MODEPREFS($mode,menu,$menu)
  405.     pack $w.$menu -expand y -fill x
  406.   }
  407.   
  408.   return $w
  409. }
  410.